using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;

namespace myGCalendar {
    class EventPanel : TableLayoutPanel {

        private ArrayList calEvents;
        private ArrayList ltime = new ArrayList();
        private ArrayList lwhat = new ArrayList();
        private ArrayList lwhere = new ArrayList();
        //private bool active;
        
        public EventPanel(ArrayList e) {
            calEvents = e;

            InitializeComponents();            
        }

        private void InitializeComponents() {
            
            this.Margin = new Padding(0);
            this.BackColor = Color.White;
            this.AutoSize = true;
            this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.ColumnCount = 2;

            this.RowCount = 2*calEvents.Count;

            int row=0;
            foreach(CalEvent e in calEvents) {
                Label time = new Label();
                Label what = new Label();
                Label where = new Label();
                Color col;

                if (e.StartTime < DateTime.Now && !e.AllDay)
                    col = Color.Gray;
                else
                    col = e.Color;
                                
                if(e.Location!=null && e.Location.Length>0)
                    this.Controls.Add(where, 1, row+1);

                if (e.AllDay) {
                    time.Text = "All Day";
                    //time.BackColor = e.Color;
                }
                else
                    time.Text = e.StartTime.ToShortTimeString();
                time.AutoSize = true;
                time.ForeColor = col;
                //time.BorderStyle = BorderStyle.FixedSingle;

                what.Text = e.Title;
                what.AutoSize = true;
                what.ForeColor = col;
                //what.BorderStyle = BorderStyle.FixedSingle;

                where.Text = e.Location;
                where.AutoSize = true;
                where.ForeColor = col;
                //where.BorderStyle = BorderStyle.FixedSingle;

                ltime.Add(time);
                lwhat.Add(what);
                lwhere.Add(where);

                this.Controls.Add(time, 0, row);
                this.Controls.Add(what, 1, row);
                Label line = new Label();
                line.AutoSize = true;
                line.Height = 10;
                this.Controls.Add(line, 0, row + 2);
         
                row=row+3;
            }
        }

        public void checkActive() {
            this.Controls.Clear();
            InitializeComponents();
        }
    }
}
